<include file="public@header"/>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="layui-input" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}" title="图片名称" style="width:200px;">
   
        <img id="photo-{id}-preview" src="{url}" onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('{:lang('UPLOAD_IMAGE')}','#photo-{id}');">{:lang('REPLACE')}</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">{:lang('REMOVE')}</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="layui-input" id="file-{id}-name" type="text" name="file_names[]" value="{name}" title="文件名称" style="width:200px;">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('附件上传','#file-{id}','file');">{:lang('REPLACE')}</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">{:lang('REMOVE')}</a>
    </li>
</script>
</head>
<body>
<div class="layui-fluid js-check-wrap">
    <div class="layui-card">
        <div class="layui-card-header">{:lang('PORTAL_ADMINREPAIR_ADD')}</div>
        <form action="{:url('AdminArticle/addPost')}" method="post" class="layui-form js-ajax-form" data-replace="1">
            <div class="layui-card-body">
                <div class="layui-tab">
                    <ul class="layui-tab-title">
                        <li class="layui-this">
                            <span class="icon-wrapper"><i class="fa fa-align-center"></i></span>
                            <span class="text-wrapper">{:lang('PORTAL_ADMINREPAIR_ADD')}</span>
                        </li>
                        <!-- <li>
                            <span class="icon-wrapper"><i class="fa fa-cog"></i></span>
                            <span class="text-wrapper">{:lang('SEO_OPT')}</span>
                        </li> -->
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-card-body">
                                <!-- 文章标题 -->
                                <if condition="in_array('title',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('COMMON_TITLE')}</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" name="post[post_title]" data-field="article_title"
                                                placeholder="{:lang('PLEASE_ENTER')}{:lang('COMMON_TITLE')}"/>
                                    </div>
                                </div>
                                </if>

                                <!-- <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('ARTICLE_SUBTITLE')}</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" name="post[post_subtitle]" placeholder="{:lang('PLEASE_ENTER')}{:lang('ARTICLE_SUBTITLE')}"/>
                                    </div>
                                </div> -->

                                <!-- 文章分类 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('REPAIR_CATEGORY')}</label>
                                    <div class="layui-input-block">
                                        <!-- 多选分类 -->
                                        <!-- <input class="layui-input" type="text"
                                               value="{$category['name']}"
                                               placeholder="{:lang('PLEASE_SELECTED_CATEGORY')}" onclick="doSelectCategory();" id="js-categories-name-input"
                                               readonly/>
                                        <input class="layui-input" type="hidden" value="{$category['id']}"
                                               name="post[categories]"
                                               id="js-categories-id-input"/> -->

                                        <!-- 单选分类 -->
                                        <select class="layui-input" name="post[categories]">
                                            <option value=''>{:lang('SELECT_PLEASE')}{:lang('REPAIR_CATEGORY')}</option>
                                            {$category_tree|default=''}
                                        </select>
                                    </div>
                                </div>

                                <!-- 故障地点 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">故障地点</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input" type="text" name="post[repair_place]" value="" placeholder="请填写故障地点">
                                    </div>
                                </div>

                                <!-- 发布时间 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('PUBLISHED_TIME')}</label>
                                
                                    <div class="layui-input-block">
                                        <input class="layui-input js-layui-datetime" type="text" name="post[published_time]"
                                               value="{:date('Y-m-d H:i:s',time())}" id="published_time" readonly>
                                    </div>
                                </div>

                                <!-- 文章来源 -->
                               <!--  <if condition="in_array('source',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('ARTICLE_SOURCE')}</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" id="post_source" name="post[post_source]" data-field="article_source"
                                               placeholder="{:lang('PLEASE_ENTER')}{:lang('ARTICLE_SOURCE')}">
                                    </div>
                                </div>
                                </if> -->

                                <!-- 内容摘要 -->
                                <!-- <if condition="in_array('excerpt',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('ARTICLE_EXCERPT')}</label>
                                    <div class="layui-input-block">
                                        <script class="form-replace" type="text/plain" id="post_excerpt" name="post[post_excerpt]"></script>
                                    </div>
                                </div>
                                </if> -->

                                <!-- 详细内容 -->
                                <if condition="in_array('content',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('REPAIR_CONTENT')}</label>
                                    <div class="layui-input-block">
                                        <script class="form-replace" type="text/plain" id="detail_content" name="post[post_content]"></script>
                                    </div>
                                </div>
                                </if>

                                <!-- 上传图片 -->
                                <!-- <if condition="in_array('thumb',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('UPLOAD_IMAGE')}</label>
                                
                                    <div class="layui-input-block">
                                        <div class="upload-image">
                                            <input type="hidden" name="post[more][thumbnail]" id="thumbnail"
                                                   value="">
                                            <a href="javascript:uploadOneImage('{:lang('UPLOAD_IMAGE')}','#thumbnail');">
                                                <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                     id="thumbnail-preview"
                                                     width="150"/>
                                            </a>
                                            <input type="button" class="layui-btn layui-btn-danger layui-btn-md btn-cancel-thumbnail" value="{:lang('CANCEL_PICTURE')}">
                                        </div>
                                    </div>
                                </div>
                                </if> -->

                                <!-- 图片推荐尺寸 -->
                                <notempty name="category['id']">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">{:lang('PICTURE_RECOMMENDED_SIZE')}</label>
                                        <div class="layui-input-block">
                                            <table class="layui-table thumb-size" style="max-width:500px;" lay-size="sm">
                                                <tr>
                                                    <td>{:lang('CATEGORY')}</td>
                                                    <td>{:lang('IMAGE_SIZE')}</td>
                                                </tr>
                                                <tr>
                                                    <td>{$category.name}</td>
                                                    <td>{$category.thumb_size}</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </notempty>

                                <!-- 相册 -->
                                <if condition="in_array('album',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">相册</label>
                                    <div class="layui-input-block">
                                        <ul id="photos" class="pic-list list-unstyled form-inline"></ul>
                                        <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                                           class="layui-btn layui-btn-normal">选择图片</a>
                                    </div>
                                </div>
                                </if>

                                <!-- 选择维修人员 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">选择维修人员</label>
                                    <div class="layui-input-block">
                                        <!-- 单选分类 -->
                                        <select class="layui-input" name="post[repairman_id]">
                                            <option value=''>请选择维修人员</option>
                                            <foreach name="member_list" item="vo">
                                                <option value='{$vo.id}'>{$vo.user_login}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>

                                <!-- 附件 -->
                                <!-- <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('UPLOAD_FILE')}</label>
                                    <div class="layui-input-block">
                                        <ul id="files" class="pic-list list-unstyled form-inline"></ul>
                                        <a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl');"
                                           class="layui-btn layui-btn-normal">选择文件</a>
                                    </div>
                                </div> -->

                                <!-- <div class="layui-form-item">
                                    <label class="layui-form-label">坐标</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="post[more][location_text]" class="layui-input"
                                               onclick="doSelectLocation(this)"
                                               placeholder="请选择坐标"
                                               value="{$post['more']['location_text']|default=''}">
                                        <input type="hidden" name="post[more][location]" class="layui-input"
                                               value="{$post['more']['location']|default=''}">
                                    </div>
                                </div> -->

                                <!-- <notempty name="field_status_list">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">{:lang('ATTRIBUTE')}</label>
                                        <div class="layui-input-block">
                                            <div class="checkbox">
                                                <if condition="in_array('status_is_top',$field_list)">
                                                    <input type="checkbox" name="post[is_top]" title="{:lang('IS_TOP')}" value="1">
                                                </if>

                                                <if condition="in_array('status_recom',$field_list)">
                                                    <input type="checkbox" name="post[recommended]" title="{:lang('RECOMMENDED')}" value="1">
                                                </if>
                                            </div>
                                        </div>
                                    </div>
                                </notempty> -->

                                <!-- 模版 -->
                                <!-- <if condition="in_array('template',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">文章模板</label>
                                
                                    <div class="layui-input-block">
                                        <select class="layui-input" name="post[more][template]" id="more-template-select">
                                            <option value="">请选择模板</option>
                                            <foreach name="article_theme_files" item="vo">
                                                <php>$value=preg_replace('/^repair\//','',$vo['file']);</php>
                                                <option value="{$value}">{$vo.name} {$vo.file}.html</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                </if> -->
                            </div>
                        </div>

                        <!-- <div class="layui-tab-item">
                            <div class="layui-card-body">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('PAGE_TITLE')}</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" name="post[page_title]" data-field="page_title"       placeholder="{:lang('PLEASE_ENTER')}{:lang('PAGE_TITLE')}">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('PAGE_KEYWORDS')}</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" name="post[page_keywords]" data-field="page_keywords"
                                               placeholder="{:lang('PLEASE_ENTER')}{:lang('PAGE_KEYWORDS')}">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('PAGE_DESCRIPTION')}</label>
                                    <div class="layui-input-block">
                                        <textarea class="layui-textarea form-replace" name="post[page_description]" rows="5"  data-field="page_description"
                                                  placeholder="{:lang('PLEASE_FILL_IN')}{:lang('PAGE_DESCRIPTION')}"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div> -->
                    </div>
                </div>

                <div class="layui-form-item padding-left-25">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-normal" onclick="CheckSenSubmit();" id="add-key">{:lang('ADD')}</button>
                        <button type="submit" class="layui-btn layui-btn-normal js-ajax-submit" style="display:none;" id="js-ajax-submit">{:lang('ADD')}</button>
                        <!-- <button type="button" class="layui-btn layui-btn-normal content-preview" onclick="contentPreview(editorcontent,'title','published_time');" id="add-key">{:lang('PREVIEW')}</button> -->
                        <a class="layui-btn layui-btn-primary" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>

        </form>
    </div>
</div>

<include file="public@footer"/>
<include file="admin@theme/scripts"/>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
    $(function () {
        if( $('#detail_content').length ){
            // $('.content-preview').show();
            UE.getEditor('detail_content');
        }
        if( $('#post_excerpt').length ){
            UE.getEditor('post_excerpt');
        }
        //移除缩略图
        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });

    // 选择分类
    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?operate=add&ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
